﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;

namespace S2_SmartCode
{
    public partial class CreateCode : Form
    {
        /// <summary>
        /// Model层命名空间名称
        /// </summary>
        protected string StrModel = ConfigurationManager.AppSettings["Model"];

        /// <summary>
        /// 数据库连接字符串
        /// </summary>
        protected static string Con = ConfigurationManager.AppSettings["ConnectionString"];

        public CreateCode()
        {
            InitializeComponent();
            BindData();
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            string strModel = this.lblSelectedTable.Text;
            if (!string.IsNullOrEmpty(strModel))
            {
                try
                {
                    Model.Create(StrModel, strModel);

                    MessageBox.Show("生成成功!");
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }

        protected void BindData()
        {
            DataTable dt = Common.LoadDataTable();

            this.lstboxTable.DataSource = dt;
            this.lstboxTable.DisplayMember = "TABLE_NAME";

            
        }

        private void lstboxTable_SelectedValueChanged(object sender, EventArgs e)
        {
            if (this.lstboxTable.SelectedIndex != -1)
            {
                this.lblSelectedTable.Text = this.lstboxTable.Text;
                this.btnSubmit.Enabled = true;
            }
            else
            {
                this.btnSubmit.Enabled = false;
            }

        }
    }
}
